<%@ page import="com.symc.sims0213xfw.bean.College" %>
<%@ page import="java.util.List" %>
<%@ page import="com.symc.sims0213xfw.service.impl.CollegeServiceImpl" %>
<%@ page import="com.symc.sims0213xfw.service.impl.DepartmentServiceImpl" %><%--
  Created by IntelliJ IDEA.
  User: 凤文 0213
  Date: 2022/1/16
  Time: 18:13
  Description: 
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加学生</title>
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
    <script type="text/javascript">
        //测试引用是否成功
        $(document).ready(function (e) {
            alert('当前为添加学生的页面！');
        });
    </script>
</head>
<body>
<form action="/SMIS0213xfw/addStudentServlet" method="get">
    <%
        session.setAttribute("college", new CollegeServiceImpl().getOptionalCollegeList());
    %>
    <h4>学院</h4>
    <select id="selectedCollege">

        <option>--请选择学院--</option>
        <%
            List<College> colleges =
                    (List<College>) session.getAttribute("college");
            for (College college : colleges) {
        %>
        <option>
            <%
                out.write(college.getName());
            %>
        </option>
        <%
            }
        %>
    </select>

    <h4>专业</h4>
    <select id="selectedDepartment" name="selectedDepartment">
        <option>--请选择专业--</option>
    </select>

    <h4>年级</h4>
    <select id="selectedGrade" name="selectedGrade">
        <option>--请选择年级--</option>
    </select>

    <h4>班级</h4>
    <select id="selectedClasses" name="selectedClasses">
        <option>--请选择班级--</option>
    </select>

    <h4>学号</h4>
    <input name="id"><br>
    <h4>姓名</h4>
    <input name="name"><br>
    <button type="submit">添加</button>
</form>

<script>
    $("#selectedCollege").blur(function () {
        let college = $("#selectedCollege").val();
        if (college == "--请选择学院--") {
            return;
        }
        $.ajax({
            url: "../../multistageTandemServlet",
            data: {"selectedCollege": college},
            type: "GET",
            dataType: "json",
            success: function (data) {//将返回的数据显示到标签
                var options = "<option>--请选择专业--</option>";
                for (let i = 0; i < data.length; i++) {
                    options += "<option>" + data[i].name + "</option>";
                }
                $("#selectedDepartment").html(options);
            }
        });
    });

    $("#selectedDepartment").blur(function () {
        let department = $("#selectedDepartment").val();
        if (department == "--请选择年级--") {
            return;
        }
        $.ajax({
            url: "../../multistageTandemServlet",
            data: {"selectedDepartment": department},
            type: "GET",
            dataType: "json",
            success: function (data) {//将返回的数据显示到标签
                var options = "<option>--请选择年级--</option>";
                for (let i = 0; i < data.length; i++) {
                    options += "<option>" + data[i].grade + "</option>";
                }
                $("#selectedGrade").html(options);
            }
        });
    });

    $("#selectedGrade").blur(function () {
        let grade = $("#selectedGrade").val();
        if (grade == "--请选择班级--") {
            return;
        }
        $.ajax({
            url: "../../multistageTandemServlet",
            data: {"selectedGrade": grade},
            type: "GET",
            dataType: "json",
            success: function (data) {
                var options = "<option>--请选择班级--</option>";
                for (let i = 0; i < data.length; i++) {
                    options += "<option>" + data[i].name + "</option>";
                }
                $("#selectedClasses").html(options);
            }
        });
    });
</script>
</body>
</html>
